home *** CD-ROM | disk | FTP | other *** search
/ Champak 29 / Volume 29 - JOGO DISK .iso / Games / jungle_adventure.swf / scripts / __Packages / GamePlayer.as < prev    next >
Text File  |  2006-11-29  |  2KB  |  96 lines

  1. class GamePlayer
  2. {
  3.    var score = 0;
  4.    var health = 1;
  5.    var lives = 3;
  6.    var shield = 0;
  7.    var fuel = 0;
  8.    var left = false;
  9.    var right = false;
  10.    var up = false;
  11.    var down = false;
  12.    var jump = false;
  13.    var action = false;
  14.    function GamePlayer()
  15.    {
  16.       this.initialize();
  17.       this.lives = !_global.VR_ON_LIVES ? 3 : 5;
  18.    }
  19.    function initialize()
  20.    {
  21.       Key.addListener(this);
  22.    }
  23.    function destroy()
  24.    {
  25.       Key.removeListener(this);
  26.    }
  27.    function setControl(obj)
  28.    {
  29.       this.control.deactivate();
  30.       this.control.active = false;
  31.       this.control = obj;
  32.       obj.controller = this;
  33.       obj.active = true;
  34.       obj.activate();
  35.    }
  36.    function shiftScore(value)
  37.    {
  38.       this.score += value;
  39.    }
  40.    function update(elapsed)
  41.    {
  42.       this.control.update(elapsed);
  43.       this.clearKeys();
  44.    }
  45.    function onKeyDown()
  46.    {
  47.       if(this.lastKey == (this.lastKey = Key.getCode()))
  48.       {
  49.          return undefined;
  50.       }
  51.       switch(this.lastKey)
  52.       {
  53.          case 37:
  54.             this.left = true;
  55.             break;
  56.          case 38:
  57.             this.up = true;
  58.             break;
  59.          case 39:
  60.             this.right = true;
  61.             break;
  62.          case 40:
  63.             this.down = true;
  64.             break;
  65.          case 32:
  66.             this.jump = true;
  67.             break;
  68.          case 68:
  69.             this.action = true;
  70.       }
  71.    }
  72.    function onKeyUp()
  73.    {
  74.       switch(Key.getCode())
  75.       {
  76.          case 37:
  77.             this.left = false;
  78.             break;
  79.          case 38:
  80.             this.up = false;
  81.             break;
  82.          case 39:
  83.             this.right = false;
  84.             break;
  85.          case 40:
  86.             this.down = false;
  87.       }
  88.       this.lastKey = 0;
  89.    }
  90.    function clearKeys()
  91.    {
  92.       this.jump = false;
  93.       this.action = false;
  94.    }
  95. }
  96.